package server;

import util.MyParser;

public class TimerThread extends Thread {
	private ReceiveMonitor rm;
	private int current;

	public TimerThread(int limit, ReceiveMonitor rm) {
		current = limit;
		this.rm = rm;
	}

	public void run() {
		while (current > 0) {
			current--;
			try {
				sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		if (current == 0) {
			rm.setMessage(MyParser.SERVER + MyParser.FIELD + "END", "Server");
		}
	}

	public void halt() {
		current = -1;
	}

	public int getTime() {
		return current;
	}
}
